// 参考: https://json-schema.org/understanding-json-schema/reference/
// 最新草案: http://json-schema.org/latest/json-schema-validation.html

module.exports = {
  "type": "object",
  "additionalProperties": false,
  "required": [
    "name",
    "age"
  ],
  "errorMessage": {
    "type": "必须为对象",
    "additionalProperties": "不能包含其他属性",
    "required": "缺乏必传项"
  },
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 20,
      "errorMessage": {
        "type": "名字必须为字符串",
        "minLength": "年龄长度必须大于1",
        "maxLength": "年龄长度必须小于20"
      }
    },
    "age": {
      "type": "integer",
      "minimum": 0,
      "exclusiveMaximum": 140,
      "errorMessage": {
        "type": "年龄必须为整数",
        "minimum": "年龄必须大于等于0",
        "exclusiveMaximum": "年龄必须小于140"
      }
    },
    "sex": {
      "type": "integer",
      "enum": [0, 1, 2],
      "errorMessage": {
        "type": "性别必须为整数",
        "enum": "性别可选值为0,1,2"
      }
    },
    "height": {
      "type": "number",
      "errorMessage": {
        "type": "身高必须为数字"
      }
    },
    "graduated": {
      "type": "boolean",
      "errorMessage": {
        "type": "是否毕业必须为true或false"
      }
    },
    "hobby": {
      "type": "array",
      "minItems": 3,
      "maxItems": 6,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "errorMessage": {
          "type": "每一项爱好必须为字符串类型",
        }
      },
      "errorMessage": {
        "type": "爱好必须为数组类型",
        "minItems": "爱好应大于3项(含)",
        "maxItems": "爱好应少于6项(含)",
        "uniqueItems": "爱好不能重复",
      }
    },
    "email": {
      "type": "string",
      "format": "email",
      "errorMessage": {
        "type": "邮箱地址必须为字符串类型",
        "format": "邮箱地址格式不正确",
      }
    },
    "ip": {
      "type": "string",
      "format": "ipv4",
      "errorMessage": {
        "type": "ipv4必须为字符串类型",
        "format": "ipv4格式不正确",
      }
    },
    "coorinate": {
      "type": "object",
      "required": [ "latitude", "longitude" ],
      "properties": {
        "latitude": {
          "type": "number",
          "minimum": -90,
          "maximum": 90,
          "errorMessage": {
            "type": "纬度必须为数字类型",
            "minimum": "纬度取值范围为-90(含)到90(含)之间",
            "maximum": "纬度取值范围为-90(含)到90(含)之间",
          }
        },
        "longitude": {
          "type": "number",
          "minimum": -180,
          "maximum": 180,
          "errorMessage": {
            "type": "经度必须为数字类型",
            "minimum": "经度取值范围为-180(含)到180(含)之间",
            "maximum": "经度取值范围为-180(含)到180(含)之间",
          }
        }
      },
      "errorMessage": {
        "type": "坐标必须为对象类型",
        "required": "坐标对象必须包含latitude和longitude属性",
      }
    }
  }
}

// 对象